package com.example.anql.service.impl;

import com.example.anql.common.ReturnObject;
import com.example.anql.common.ReturnUtil;
import com.example.anql.entity.GetShop;
import com.example.anql.dao.GetShopDao;
import com.example.anql.service.GetShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (GetShop)表服务实现类
 *
 * @author makejava
 * @since 2022-12-10 12:46:24
 */
@Service("getShopService")
public class GetShopServiceImpl implements GetShopService {
    @Resource
    private GetShopDao getShopDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GetShop queryById(Integer id) {
        return this.getShopDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param getShop 筛选条件
     * @return 查询结果
     */
    @Override
    public ReturnObject queryByPage(GetShop getShop ) {
        PageHelper.startPage(getShop.getPage(),getShop.getSize());
        List<GetShop> listUser = getShopDao.queryByPage(getShop);
        PageInfo<GetShop> pageInfo = new PageInfo<>(listUser);
        return ReturnUtil.success(pageInfo);

    }

    /**
     * 新增数据
     *
     * @param getShop 实例对象
     * @return 实例对象
     */
    @Override
    public GetShop insert(GetShop getShop) {
        this.getShopDao.insert(getShop);
        return getShop;
    }

    /**
     * 修改数据
     *
     * @param getShop 实例对象
     * @return 实例对象
     */
    @Override
    public GetShop update(GetShop getShop) {
        this.getShopDao.update(getShop);
        return this.queryById(getShop.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.getShopDao.deleteById(id) > 0;
    }
}
